﻿using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;

namespace DailyApp.API.Models
{
    public partial class STJCAMContext : DbContext
    {
        private readonly IConfiguration _configuration;
        public STJCAMContext()
        {
        }

        public STJCAMContext(DbContextOptions<STJCAMContext> options, IConfiguration configuration)
            : base(options)
        {
            _configuration = configuration;
        }

        public virtual DbSet<EfmShareFolderPermission> EfmShareFolderPermissions { get; set; } = null!;
        public virtual DbSet<EfmUser> EfmUsers { get; set; } = null!;

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            if (!optionsBuilder.IsConfigured)
            {
#warning To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see http://go.microsoft.com/fwlink/?LinkId=723263.
               
                optionsBuilder.UseSqlServer(_configuration.GetConnectionString("STJCAMWriteString")); 
            }
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<EfmShareFolderPermission>(entity =>
            {
                entity.HasKey(e => new { e.Badge, e.FilePath });

                entity.ToTable("EFM_ShareFolder_Permissions");

                entity.Property(e => e.Badge).HasMaxLength(50);

                entity.Property(e => e.FilePath)
                    .HasMaxLength(300)
                    .IsUnicode(false);

                entity.Property(e => e.CreateBy)
                    .HasMaxLength(30)
                    .IsUnicode(false)
                    .HasColumnName("Create_by");

                entity.Property(e => e.CreateTime)
                    .HasColumnType("datetime")
                    .HasColumnName("Create_time");

                entity.Property(e => e.Name).HasMaxLength(100);

                entity.Property(e => e.Permissions)
                    .HasMaxLength(10)
                    .IsUnicode(false);

                entity.Property(e => e.Rowguid).HasColumnName("rowguid");

                entity.Property(e => e.Status)
                    .HasMaxLength(5)
                    .IsUnicode(false);
            });

            modelBuilder.Entity<EfmUser>(entity =>
            {
                entity.HasKey(e => e.Badge);

                entity.ToTable("EFM_User");

                entity.Property(e => e.Badge)
                    .HasMaxLength(15)
                    .IsUnicode(false);

                entity.Property(e => e.Cname)
                    .HasMaxLength(30)
                    .HasColumnName("CName");

                entity.Property(e => e.CreateBy)
                    .HasMaxLength(30)
                    .IsUnicode(false)
                    .HasColumnName("Create_by");

                entity.Property(e => e.CreateTime)
                    .HasColumnType("datetime")
                    .HasColumnName("Create_time");

                entity.Property(e => e.Dept)
                    .HasMaxLength(10)
                    .IsUnicode(false);

                entity.Property(e => e.Name)
                    .HasMaxLength(30)
                    .IsUnicode(false);

                entity.Property(e => e.Password)
                    .HasMaxLength(30)
                    .IsUnicode(false);

                entity.Property(e => e.Permission)
                    .HasMaxLength(30)
                    .IsUnicode(false);

                entity.Property(e => e.Rowguid).HasColumnName("rowguid");

                entity.Property(e => e.Site)
                    .HasMaxLength(30)
                    .IsUnicode(false);
            });

            OnModelCreatingPartial(modelBuilder);
        }

        partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
    }
}
